package jp.sourceforge.talisman.mds.cluster;

/*
 * $Id: AbstractClusteringMethod.java,v 1.1 2009/09/12 05:06:02 weiwei Exp $
 */

import jp.sourceforge.talisman.mds.CalculationFailException;
import jp.sourceforge.talisman.mds.Item;
import jp.sourceforge.talisman.mds.distance.ItemDistanceCalculator;

/**
 * 
 * @author Haruaki Tamada
 * @version $Revision: 1.1 $ 
 */
public abstract class AbstractClusteringMethod implements ClusteringMethod{
    private ClusteringParameter param;

    public AbstractClusteringMethod(ClusteringParameter param){
        this.param = param;
        if(param == null){
            throw new NullPointerException();
        }
    }

    public ItemDistanceCalculator getDistanceCalculator(){
        return param.getDistanceCalculator();
    }

    public final Cluster[] clustering(Item[] items) throws CalculationFailException{
        return clustering(items, param);
    }

    public final Cluster[] clustering(Item[] items, ClusteringParameter param) throws CalculationFailException{
        if(!param.isValid(items)){
            throw new InvalidParameterException(param.toString());
        }
        return doClustering(items, param);
    }

    protected abstract Cluster[] doClustering(Item[] items, ClusteringParameter param);
}
